package compare;

import java.util.Comparator;

class Person2 {
	String name;
	int age;
	public Person2(String name, int age) {
		this.name = name;
		this.age = age;
	}
	@Override
	public String toString() {
		return "Person2 [name=" + name + ", age=" + age + "]";
	}
}
class Mom implements Comparator<Person2>{
	// 前大返回正，后大返回负，一样大返回0
	@Override
	public int compare(Person2 o1, Person2 o2) {
		return o1.age - o2.age;
	}
}
public class ComparatorDemo {
	public static void main(String[] args) {
		Person2 p1 = new Person2("lis",20);
		Person2 p2 = new Person2("zs",30);
		Mom m = new Mom();
		System.out.println(m.compare(p1, p2));
	}
}
